wayland: Fix memory handling for the selection callbacks
authorRob Bradford <rob@linux.intel.com>
Fri, 13 Jan 2012 15:42:53 +0000 (15:42 +0000)
committerRob Bradford <rob@linux.intel.com>
Fri, 13 Jan 2012 16:50:47 +0000 (16:50 +0000)
gdk/wayland/gdkdevice-wayland.c
gdk/wayland/gdkwayland.h

index c7ea5aa8f41f7c06caf09d5ffb9b94dffbc423c4..26faad8ac5da7c8b69e909649f176f153a8b3f2f 100644 (file)
@@ -1007,6 +1007,7 @@ _request_content_io_func (GIOChannel *channel,
 
   closure->cb (closure->device->pointer, data, len, closure->userdata);
 
+  g_free (data);
   data_offer_unref (closure->offer);
   g_io_channel_unref (channel);
   g_free (closure);
@@ -1099,8 +1100,8 @@ data_source_send (void                  *data,
                   int32_t                fd)
 {
   GdkWaylandSelectionOffer *offer = (GdkWaylandSelectionOffer *)data;;
-  const gchar *buf;
-  gssize len, bytes_written;
+  gchar *buf;
+  gssize len, bytes_written = 0;
 
   g_debug (G_STRLOC ": %s source = %p, mime_type = %s fd = %d",
            G_STRFUNC, source, mime_type, fd);
@@ -1109,13 +1110,14 @@ data_source_send (void                  *data,
 
   while (len > 0)
     {
-      bytes_written = write (fd, buf, len);
+      bytes_written += write (fd, buf + bytes_written, len);
       if (bytes_written == -1)
         goto error;
       len -= bytes_written;
     }
 
   close (fd);
+  g_free (buf);
 
   return;
 error:
@@ -1124,6 +1126,7 @@ error:
              g_strerror (errno));
 
   close (fd);
+  g_free (buf);
 }
 
 static void
index 8c964c99b92ab62d647a47049fc6dcb455808a0a..97d5ad21e9955d00e1d23b35be5e0e1a71db7527 100644 (file)
@@ -39,7 +39,7 @@ int
 gdk_wayland_device_get_selection_type_atoms (GdkDevice  *device,
                                              GdkAtom   **atoms_out);
 
-typedef void (*GdkDeviceWaylandRequestContentCallback) (GdkDevice *device, gchar *data, gsize len, gpointer userdata);
+typedef void (*GdkDeviceWaylandRequestContentCallback) (GdkDevice *device, const gchar *data, gsize len, gpointer userdata);
 
 #define gdk_wayland_device_request_selection_content gdk_wayland_device_request_selection_content_libgtk_only
 gboolean
@@ -48,7 +48,7 @@ gdk_wayland_device_request_selection_content (GdkDevice
                                               GdkDeviceWaylandRequestContentCallback  cb,
                                               gpointer                                userdata);
 
-typedef const gchar *(*GdkDeviceWaylandOfferContentCallback) (GdkDevice *device, const gchar *mime_type, gssize *len, gpointer userdata);
+typedef gchar *(*GdkDeviceWaylandOfferContentCallback) (GdkDevice *device, const gchar *mime_type, gssize *len, gpointer userdata);
 
 #define gdk_wayland_device_offer_selection_content gdk_wayland_device_offer_selection_content_libgtk_only
 gboolean